package com.gofull.gateway.sms.util;

import java.io.UnsupportedEncodingException;
import java.rmi.RemoteException;

import javax.xml.rpc.ServiceException;

import com.gofull.gateway.sms.vo.WmgwLocator;

/**
 * 短信接口，对短信接口地址进行拼接，提供公用
 * 
 * @author Administrator
 * 
 */
public class SMSUtil {


	/**   
	 * @MethodName: sendSMS  
	 * @Param: SMSUtil  
	 * @Author: gang.lv
	 * @Date: 2013-5-30 下午04:04:13
	 * @Return:    
	 * @Descb: 发送短信
	 * @Throws:
	*/
//	public static String sendSMS(String userName, String password, String content,
//			String phone,String randomCode) {
//		try {
//			if(randomCode != null){
//				content += randomCode;
//			}
//			//if (!IConstants.ISDEMO.equals("1")) {
//				SMS.sendMSM(userName, password, content, phone);
//			//}
//			return "Sucess";
//		} catch (RemoteException e) {
//			e.printStackTrace();
//			return "Fail";
//		} catch (ServiceException e) {
//			e.printStackTrace();
//			return "Fail";
//		}
//	}
	/**   
	 * @MethodName: sendSMS  
	 * @Param: SMSUtil  
	 * @Author: wujc
	 * @Date: 2014-1-20 
	 * @Return:    
	 * @Descb: 通过亿美client包，直接发送短信
	 * @Throws:
	*/
//	public static String sendSMS(String userName, String password, String content,
//			String phone,String randomCode) {
//		try {
//			if(randomCode != null){
//				content += randomCode;
//			}
//			int i=SingletonClient.getClient(userName,password).sendSMS(new String[] {phone}, content,"",5);//带扩展码
//			System.out.println("testSendSMS====="+content+phone);//0表示短信发送成功
//			return "Sucess";
//		} catch (Exception e) {
//			e.printStackTrace();
//			return "Fail";
//		} 
//	}
//
//}

	/**   
	 * @MethodName: sendSMS  
	 * @Param: SMSUtil  
	 * @Author: wujc
	 * @Date: 2014-1-20 
	 * @Return:    
	 * @Descb: 通过梦网科技，直接发送短信
	 * @Throws:
	*/
	public static String sendSMS(String userName, String password, String content,
			String phone,String randomCode)throws UnsupportedEncodingException {
		
		if(randomCode != null){
			content += randomCode;
		}
		
		WmgwLocator wmgwLocator = new WmgwLocator();
		//String strMsg = new String(content.getBytes("UTF-8"));//编码utf-8
		try {
			System.out.println("mongateCsSendSmsExNew begin...");
			String backValue = wmgwLocator.getwmgwSoap().mongateCsSpSendSmsNew(userName,
					password, phone, content, 1,"*");
			System.out.println("back value is :" + backValue + content);
			System.out.println("send mongateCsSendSmsExNew end !");
			if(backValue.length()>10 && backValue.length()<25){
				return "Sucess";
			}else{
				return "Fail";
			}			
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return "Fail";
		} catch (ServiceException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return "Fail";
		}
	}

}
	
